package com.siss.tenancy.export;



import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * 字典工具类
 * @author wangzm
 * @version 2013-5-29
 */
public class DictUtils {


    public static final String CACHE_DICT_MAP = "dictMap";

    public static String getDictName(String code, String value, String defaultLabel){
        return defaultLabel;
    }

    /*
     * 反射根据对象和属性名获取属性值
     */
    public static Object getValue(Object obj, String filed) {
        try {
            Class clazz = obj.getClass();
            PropertyDescriptor pd = new PropertyDescriptor(filed, clazz);
            Method getMethod = pd.getReadMethod();//获得get方法

            if (pd != null) {

                Object o = getMethod.invoke(obj);//执行get方法返回一个Object
                return o;

            }
        } catch (SecurityException e) {
            e.printStackTrace();
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (IntrospectionException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }

        return null;
    }
}
